package com.droidclaimsurveyor.bl;

import android.content.Context;

import com.droidclaimsurveyor.dal.CarImageDal;
import com.droidclaimsurveyor.dal.DatabaseLoader;
import com.droidclaimsurveyor.helper.asyntask.ICompleteListener;
import com.droidclaimsurveyor.model.CarImageModel;

public class CarImageBl {
	ICompleteListener listener;
	

	public CarImageBl(ICompleteListener listener) {
		this.listener = listener;
	}

	public String GetAllCarImage(String claimId) {
		DatabaseLoader<CarImageModel, String> dbLoader = new DatabaseLoader<CarImageModel, String>(
				(Context) listener, "GetAllCarImage");
		String claimInfoTask = CarImageDal.GetAllCarImageId;
		dbLoader.setTaskCompletionListener(listener);
		dbLoader.setTaskId(claimInfoTask);
		CarImageDal dal = new CarImageDal((Context)listener);
		dbLoader.setDAL(dal);
		dbLoader.execute(claimId);
		
		return claimInfoTask;
	}
	
	public String GetLastCarImage(String claimId) {
		DatabaseLoader<CarImageModel, String> dbLoader = new DatabaseLoader<CarImageModel, String>(
				(Context) listener, "GetLastCarImage");
		String claimInfoTask = CarImageDal.GetLastCarImageId;
		dbLoader.setTaskCompletionListener(listener);
		dbLoader.setTaskId(claimInfoTask);
		CarImageDal dal = new CarImageDal((Context)listener);
		dbLoader.setDAL(dal);
		dbLoader.execute(claimId);
		
		return claimInfoTask;
	}
	
	public String GetCarImageByRowId(long rowId) {
		DatabaseLoader<CarImageModel, String> dbLoader = new DatabaseLoader<CarImageModel, String>(
				(Context) listener, "GetCarImageByRowId");
		String claimInfoTask = CarImageDal.GetCarImageByRowId;
		dbLoader.setTaskCompletionListener(listener);
		dbLoader.setTaskId(claimInfoTask);
		CarImageDal dal = new CarImageDal((Context)listener);
		dbLoader.setDAL(dal);
		dbLoader.execute(Long.toString(rowId));
		
		return claimInfoTask;
	}

	public long addCarImage(CarImageModel data) {
		CarImageDal dal = new CarImageDal((Context)listener);
		dal.open();
		long result = dal.add(data);
		dal.close();
		
		return result;
	}

	public boolean updateCarImage(long rowIndex, CarImageModel data) {
		CarImageDal dal = new CarImageDal((Context)listener);
		dal.open();
		boolean result = dal.update(rowIndex,data);
		dal.close();
		return result;
	}

	public boolean removeCarImage(long rowIndex) {		
		CarImageDal dal = new CarImageDal((Context)listener);
		dal.open();
		boolean result =  dal.remove(rowIndex);
		dal.close();
		return result;
	}	
}
